package com.als.healthymananger.controller.impl;

import com.als.healthymananger.controller.SuggestionsApi;
import com.als.healthymananger.entity.Suggestion;
import com.als.healthymananger.service.SuggestionsService;
import com.als.healthymananger.utils.RespBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
@RequestMapping("/lib/suggestion")
public class SuggestionsController implements SuggestionsApi {
    @Autowired
    private SuggestionsService suggestionsService;

    @Override
    public RespBean createSuggestions(Suggestion suggestion) {
        return suggestionsService.save(suggestion)? RespBean.ok("添加成功"): RespBean.badRequest("添加失败");
    }

    @Override
    public RespBean deleteSuggestions(int suggestionId) {
        return suggestionsService.removeById(suggestionId)? RespBean.ok("删除成功"): RespBean.badRequest("删除失败");
    }

    @Override
    public RespBean updateSuggestions(int suggestionId, Suggestion suggestion) {
        return suggestionsService.updateById(suggestion)? RespBean.ok("修改成功"): RespBean.badRequest("修改失败");
    }

    @Override
    public RespBean getSuggestions(int suggestionId) {
        Suggestion suggestion = suggestionsService.getById(suggestionId);
        return suggestion == null? RespBean.badRequest("获取失败"): RespBean.ok("获取成功");
    }
}
